package com.agileboot.domain.airport.reform.query;

import cn.hutool.core.util.StrUtil;
import com.agileboot.common.core.page.AbstractPageQuery;
import com.agileboot.domain.airport.reform.db.SirReformMainEntity;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Arrays;

@EqualsAndHashCode(callSuper = true)
@Data
public class ReformMainQuery extends AbstractPageQuery<SirReformMainEntity> {

    private String code;
    private String inspectors;
    private String reformStatus;
    private String questionTitle;
    private Long dutyDeptId;
    private Long issueDeptId;
    private Long curDealDeptId;



    @Override
    public QueryWrapper<SirReformMainEntity> addQueryCondition() {
        QueryWrapper<SirReformMainEntity> wrapper = new QueryWrapper<>();
        wrapper.like(StrUtil.isNotEmpty(code), "code", code)
                .like(StrUtil.isNotEmpty(inspectors), "inspectors", inspectors)
                .eq(dutyDeptId!=null, "duty_dept_id", dutyDeptId)
                .eq(issueDeptId!=null, "issue_dept_id", issueDeptId)
                .eq(curDealDeptId!=null, "cur_deal_dept_id", curDealDeptId)
                .like(StrUtil.isNotEmpty(questionTitle), "question_title", questionTitle);


        // 处理 reformStatus 字段
        if (StrUtil.isNotEmpty(reformStatus)) {
            String[] statusArray = reformStatus.split(",");
            if (statusArray.length == 1) {
                wrapper.eq("reform_status", statusArray[0]);
            } else {
                wrapper.in("reform_status", Arrays.asList(statusArray));
            }
        }

        this.setOrderColumn("check_Date");
        this.setTimeRangeColumn("check_Date");

        return wrapper;
    }
}
